package com.markus.code.exam.bianlifeng;

import java.util.Scanner;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/18 17:22
 * todo:
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            int money = scanner.nextInt();
            String s = scanner.next();
            String[] split = s.split(",");
            int []items = new int[split.length];
            for (int i=0;i<items.length;i++){
                items[i] = Integer.parseInt(split[i]);
            }
            System.out.println(buy(money,items));
        }
    }
    public static int buy(int money,int []items){
        int[][] dp = getDp(items, money);
        return dp[items.length-1][money];
    }
    private static int[][] getDp(int[] items, int money) {
        int[][] dp = new int[items.length][money + 1];
        //填基本数据
        for (int i = 0; i < items.length; i++) {
            dp[i][0] = 1;
        }
        for (int i = 1; i * items[0] <= money; i++) {
            dp[0][i * items[0]] = 1;
        }
        //填普通数据
        for (int i=1;i<items.length;i++){
            for (int j=1;j<=money;j++){
                //首先，先得出不选择当前币值的情况
                dp[i][j] = dp[i-1][j];
                //其次，再得出选择当前币值的枚举情况
                dp[i][j] += j-items[i]>=0?dp[i][j-items[i]]:0;
            }
        }
        return dp;
    }
}
